//
//  ImageModel.swift
//  photoTool
//
//  Created by 刘清元 on 2022/8/26.
//

import Foundation
@preconcurrency import WCDBSwift
//import RealmSwift
/*
 class ImageModel: Object {
 
 @Persisted var id:String = UUID.init().uuidString
 // 宽
 @Persisted var width:Int = 0
 // 高
 @Persisted var height:Int = 0
 // 文件大小
 @Persisted var fileSize:Int = 0
 // 文件名
 @Persisted var name:String = ""
 // 图片标识符
 @Persisted var localIdentifier:String = ""
 // 比例
 @Persisted var bili:Double = 0.00
 // 分组名
 @Persisted var groupName:String = ""
 // 是否删除
 @Persisted var isDelete = false
 }
 */
final class ImageModel: TableCodable,Sendable {
    var identifier: Int? = nil
    var width: Int? = nil
    var height: Int? = nil
    var fileSize: Int? = nil
    var name:String? = nil
    var localIdentifier:String? = nil
    var bili:Double? = nil
    var groupName:String? = nil
    var isDelete:Int? = nil
    var hasContrast:Int? = nil
    // 用于获取自增插入后的主键值
    var lastInsertedRowID: Int64 = 0
    // 自增
    var isAutoIncrement: Bool { true }
    enum CodingKeys: String, CodingTableKey {
        typealias Root = ImageModel
        static let objectRelationalMapping = TableBinding(CodingKeys.self) {
            // 设置属性为自增
            BindColumnConstraint(identifier, isPrimary: true)
            // 给字段设置默认值，设置是否为空
            BindColumnConstraint(width, isNotNull: true, defaultTo: 0)
            BindColumnConstraint(height, isNotNull: true, defaultTo: 0)
            BindColumnConstraint(fileSize, isNotNull: true, defaultTo: 0)
            BindColumnConstraint(name, isNotNull: true, defaultTo: "")
            BindColumnConstraint(localIdentifier, isNotNull: true, defaultTo: "")
            BindColumnConstraint(bili, isNotNull: true, defaultTo: 0)
            BindColumnConstraint(groupName, isNotNull: true, defaultTo: "")
            BindColumnConstraint(isDelete, isNotNull: true, defaultTo: 0)
            BindColumnConstraint(hasContrast,isNotNull: true,defaultTo: 0)
        }
        case identifier
        case width
        case height
        case fileSize
        case name
        case localIdentifier
        case bili
        case groupName
        case isDelete
        case hasContrast
    }
}
